package com.xdf.ecommerce.entity;

import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import com.xdf.ecommerce.account.AddressInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author chanchaw
 * @create 2025-10-25 15:48
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table("t_ecommerce_address")
public class EcommerceAddress implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id(keyType = KeyType.Auto)
    private Long id;
    private Long userId;
    private String username;
    private String phone;
    private String province;
    private String city;
    private String addressDetail;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;

    public static EcommerceAddress to(Long userId, AddressInfo.AddressItem addressItem){
        EcommerceAddress ret = new EcommerceAddress();
        ret.setUserId(userId);
        ret.setUsername(addressItem.getUsername());
        ret.setPhone(addressItem.getPhone());
        ret.setProvince(addressItem.getProvince());
        ret.setCity(addressItem.getCity());
        ret.setAddressDetail(addressItem.getAddressDetail());
        ret.setCreateTime(addressItem.getCreateTime());
        ret.setUpdateTime(addressItem.getUpdateTime());
        return ret;
    }

    public static AddressInfo.AddressItem toAddressItem(EcommerceAddress addr){
        AddressInfo.AddressItem item = new AddressInfo.AddressItem();
        item.setId(addr.getId());
        item.setUsername(addr.getUsername());
        item.setPhone(addr.getPhone());
        item.setProvince(addr.getProvince());
        item.setCity(addr.getCity());
        item.setAddressDetail(addr.getAddressDetail());
        item.setCreateTime(addr.getCreateTime());
        item.setUpdateTime(addr.getUpdateTime());
        return item;
    }
}
